<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <#include "/common/plateform/include/common-base.ftl">
    <title>版本升级检查</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

    <!-- top start -->
    <#include "/common/plateform/top.ftl">
    <!-- top end -->
    <!-- left start -->
    <#include "/common/plateform/left-project.ftl">
    <!-- left end-->

    <div class="content-wrapper">
        <!-- Main start -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">

                    <!------搜索  start ------->
                    <div class="box box-info" id="searchForm-box">
                        <!--搜索title  start -->
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-search"></i> 版本升级检查 <span class="f12">（仅检查数据表、接口、插件、菜单、数据字典等配置，在上次更新时间之后所发生变化的数据）</span></h3>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool"
                                        data-widget="collapse"><i class="fa fa-minus"></i>
                                </button>
                            </div>
                        </div>
                        <!--搜索title  end -->
                        <div class="box-body">
                            <div class="hidden">
                                <form id="searchVersionForm"  action="javascript:;">
                                    <input type="text" name="pageName" value="sys-version"/>
                                    <input type="text" name="formName" value="searchForm"/>
                                    <input type="text" name="orderBy" value="sysVersion.version_no desc"/>
                                </form>
                                <form id="saveVersionForm" action="javascript:;">
                                    <input type="text" name="pageName" value="sys-version"/>
                                    <input type="text" name="formName" value="addForm"/>
                                    <input type="text" class="sysEname" name="sysVersion.sysName" value=""/>
                                    <input type="text" name="sysVersion.versionNo" class="clean"/>
                                    <textarea name="sysVersion.remark" class="clean" row="5"></textarea>
                                </form>
                            </div>

                                <input type="hidden" name="pageName" value="sys-version">
                                <input type="hidden" name="formName" value="searchForm">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td class="w120" align="right"><div class="form-control-static">上次版本号：</div></td>
                                            <td class="w100"><div class="form-control-static" id="span_last_version"></div></td>
                                            <td class="w120" align="right"><div class="form-control-static">上次更新时间：</div></td>
                                            <td class="w250">
                                                <div class="form-group">
                                                    <div class="input-group ">
                                                        <input id="last_up_time"  name="input_startDate" maxlength="30" class="form-control clean form_datetime" readonly="readonly" type="text">
                                                        <span class="input-group-addon"> <i class="fa fa-calendar"></i></span>
                                                    </div>
                                                </div>
                                            </td>
                                            <td class="w120" align="right">
                                                <div class="form-control-static">
                                                    <input id="checkbox_this_sysname" checked type="checkbox"/> <span>仅限本系统</span>
                                                </div>
                                            </td>
                                            <td>
                                                <button type="button" class="btn btn-success" onclick="getVersionUpCheckListData();"><i class="fa fa-search"></i> 获取新版本更新内容</button>&nbsp;
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                        </div>
                    </div>
                    <!------- 搜索 end -------->

                    <div class="box box-success">
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-list"></i> 升级检查结果
                                <span id="span_version_result" class="hidden">【本次升级后最新版本号为&nbsp;<span class="red" id="span_new_version"></span>】</span>
                            </h3>
                        </div>
                        <div class="box-body mytab2" id="versionCheck-body">
                            <div class="fx3">请先点击上面“获取新版本更新内容”按钮后查看检查结果</div>
                        </div>
                        <div class="box-footer hidden" id="box-version-opt">
                            <button onclick="downloadDocFile()" class="btn btn-warning" type="button">1、查看升级查询SQL脚本</button>
                            <button id="btn_save_version" onclick="saveVersionForm()" class="btn btn-danger" type="button">2、更新升级完成，保存新版本信息</button>
                        </div>
                    </div>

                    <!------- 列表 start -------->
                    <div class="box box-success">
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-table"></i> 版本升级记录</h3>
                            <button onclick="loadCache();" class="btn btn-default btn-xs" type="button"><i class="fa fa-refresh"></i> 刷新缓存</button>
                        </div>
                        <div class="box-body mytab2">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="text-center w50">序号</th>
                                    <th class="w80">版本号</th>
                                    <th class="w100">系统</th>
                                    <th class="w150">更新时间</th>
                                    <th>更新内容说明</th>
                                    <th class="text-center w100">操作</th>
                                </tr>
                                </thead>
                                <tbody id="dataListVersion-body">
                                </tbody>
                            </table>
                            <center>
                                <ul id="dataListVersion-page"></ul>
                            </center>

                    </div>
                    <!------- 列表 end -------->
                </div>
            </div>
        </section>
        <!-- Main end -->

        <div class="modal fade" id="my_modal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title">
                            <font color="red">信息添加/修改</font>&nbsp;
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="submitForm" action="javascript:;">
                            <input type="hidden" name="pageName" value="sys-version"/>
                            <input type="hidden" name="formName" value="editForm"/>
                            <input type="" id="w_versionNo" class="clean" data-name="sysVersion.versionNo" name="sysVersion.w_versionNo" value=""/>
                            <input type="hidden" id="formToken" name="formToken" value="${formToken}"/>

                            <div class="box-body" id="submitFormData">
                                <div>
                                    <div class="tab-content">
                                        <div class="tab-pane active" id="tab_1">
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">版本号</label>
                                                <div class="col-sm-8">
                                                    <input type="text" id="versionNo"
                                                           data-name="sysVersion.versionNo" name="sysVersion.versionNo"
                                                           class="form-control clean"
                                                           placeholder="此项不能为空"
                                                           data-bv-notempty="true"
                                                           data-bv-notempty-message="此项不能为空"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">版本描述</label>
                                                <div class="col-sm-8">
                                                    <textarea id="remark" name="sysVersion.remark"
                                                           data-name="sysVersion.remark" class="form-control clean" row="5"
                                                              value=""></textarea>
                                                </div>
                                            </div>

                                        </div>
                                        <!-- /.tab-pane -->
                                    </div>
                                    <!-- /.tab-content -->
                                </div>
                                <!-- nav-tabs-custom -->
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn btn-success pull-left"
                                        onclick="mytools.closeModal('my_modal');">取消
                                </button>
                                <button type="button" class="btn btn-danger pull-right"
                                        onclick="saveItem('submitForm');">提 交
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <!-- /.modal-content -->
            </div>
        </div>

        <script type="text/template" id="dataListVersion-template">
            <? for ( var i = 0; i < rows.length; i++) {?>
            <tr>
                <td class="text-center" style="vertical-align: middle;"><?=(pageObj.currentPage-1)*10+(i+1)?></td>
                <td style="vertical-align: middle;"><?=rows[i].sysVersion.versionNo?></td>
                <td style="vertical-align: middle;"><?=rows[i].sysVersion.sysName?></td>
                <td style="vertical-align: middle;"><?=rows[i].sysVersion.createTime?></td>
                <td><div style="height:40px;font-size:10px; overflow-y:scroll;">
                        <?=rows[i].sysVersion.remark?>
                    </div></td>
                <td class="text-center" style="vertical-align: middle;">
                    <button type="button" class="btn btn-default btn-xs" onclick="del('<?=rows[i].sysVersion.versionNo?>');"><i class="fa fa-trash-o"></i> 删除</button>
                </td>
            </tr>
            <?}?>
        </script>

        <script type="text/template" id="versionCheck-template">
            <? for ( var i = 0; i < rows.length; i++) {?>
            <?var childData=rows[i].rows;?>
            <?var code=rows[i].code;?>
                <div class="box box-default box-solid collapsed-box" style="margin-bottom:3px;">
                    <div class="box-header with-border">
                        <h3 class="f14" data-no="<?=(i+1)?>" data-code="<?=code?>" data-title="<?=rows[i].title?>" data-total="<?=rows[i].total?>">
                            <?=(i+1)?>.<?=code?>-<?=rows[i].title?> 本次需更新【<span class="red"><?=rows[i].total?></span>】条数据
                        </h3>
                        <div class="box-tools pull-right"><button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button></div>
                    </div>
                    <div class="box-body no-padding" style="display: none;">
                        <table class="table table-bordered table-hover">
                            <thead>
                                <tr>
                                    <td class="w50">序号</td>
                                    <td class="w100">所属系统</td>
                                 <?if(code=='sortInfo'){?>
                                     <td class="">主键</td>
                                     <td class="">表英文名</td>
                                     <td class="">表中文名</td>
                                 <?}else if(code=='metadata'){?>
                                    <td class="">主键</td>
                                    <td class="">字段英文名</td>
                                    <td class="">字段中文名</td>
                                    <td class="">所属表中文/英文名</td>
                                <?}else if(code=='sysParamManager'){?>
                                    <td class="">主键</td>
                                    <td class="">pageName</td>
                                    <td class="">formName</td>
                                <?}else if(code=='sysPluginManager'){?>
                                    <td class="">主键</td>
                                    <td class="">插件简称</td>
                                    <td class="">插件描述</td>
                                 <?}else if(code=='sysPluginGroup'){?>
                                    <td class="">主键</td>
                                    <td class="">插件组合规则代码</td>
                                    <td class="">插件组合规则描述</td>
                                 <?}else if(code=='sysModule'){?>
                                    <td class="">主键</td>
                                    <td class="">菜单/功能标识</td>
                                    <td class="">菜单/功能名称</td>
                                 <?}else if(code=='dictDataCate'){?>
                                    <td class="">主键</td>
                                    <td class="">数据字典标识</td>
                                    <td class="">数据字典名称</td>
                                 <?}else if(code=='dictDataItem'){?>
                                    <td class="">主键</td>
                                    <td class="">字典条目标识</td>
                                    <td class="">字典条目名称</td>
                                    <td class="">所属数据字典标识</td>
                                 <?}?>
                                    <td class="w150">最后更新时间</td>
                                </tr>
                            </thead>
                            <tbody>
                            <? for ( var j = 0; j < childData.length; j++) {?>
                                <tr>
                                    <td><?=j+1?></td>
                                <?if(code=='dictDataCate'){?>
                                    <td><?=childData[j].sysEname?></td>
                                <?}else{?>
                                    <td><?=childData[j].sysName?></td>
                                <?}?>
                                 <?if(code=='sortInfo'){?>
                                    <td><?=childData[j].sortId?></td>
                                    <td><?=childData[j].infoTableName?></td>
                                    <td><?=childData[j].sortName?></td>
                                 <?}else if(code=='metadata'){?>
                                    <td><?=childData[j].metadataId?></td>
                                    <td><?=childData[j].dataShortName?></td>
                                    <td><?=childData[j].dataFullName?></td>
                                    <td><?=childData[j].sortName?>/<?=childData[j].infoTableName?></td>
                                <?}else if(code=='sysParamManager'){?>
                                    <td><?=childData[j].infoId?></td>
                                    <td><?=childData[j].pageName?></td>
                                    <td><?=childData[j].formName?></td>
                                <?}else if(code=='sysPluginManager'){?>
                                    <td><?=childData[j].infoId?></td>
                                    <td><?=childData[j].pluginShortName?></td>
                                    <td><?=childData[j].pluginRemark?></td>
                                <?}else if(code=='sysPluginGroup'){?>
                                    <td><?=childData[j].rulesId?></td>
                                    <td><?=childData[j].rulesCode?></td>
                                    <td><?=childData[j].rulesRemark?></td>
                                <?}else if(code=='sysModule'){?>
                                    <td><?=childData[j].moduleId?></td>
                                    <td><?=childData[j].code?></td>
                                    <td><?=childData[j].title?></td>
                                <?}else if(code=='dictDataCate'){?>
                                    <td><?=childData[j].cateId?></td>
                                    <td><?=childData[j].cateEname?></td>
                                    <td><?=childData[j].cateCname?></td>
                                <?}else if(code=='dictDataItem'){?>
                                    <td><?=childData[j].itemId?></td>
                                    <td><?=childData[j].itemValue?></td>
                                    <td><?=childData[j].itemText?></td>
                                    <td><?=childData[j].cateEname?></td>
                                <?}?>
                                <?if(code=='dictDataCate' || code=='dictDataItem'){?>
                                    <td title="<?=childData[j].createTime?>_<?=childData[j].updateTime?>">
                                        <?if(childData[j].updateTime>childData[j].createTime){?>
                                            <?=getFormatDateByLong(childData[j].updateTime,'yyyy-MM-dd hh:mm:ss')?>
                                        <?}else{?>
                                            <?=getFormatDateByLong(childData[j].createTime,'yyyy-MM-dd hh:mm:ss')?>
                                        <?}?>
                                    </td>
                                <?}else{?>
                                    <td title="<?=childData[j].createTime?>_<?=childData[j].modifyTime?>">
                                        <?if(code=='sortInfo' || code=='metadata'){?>
                                            <?=childData[j].createTime?>
                                        <?}else{?>
                                                <?if(childData[j].modifyTime>childData[j].createTime){?>
                                                    <?=childData[j].modifyTime?>
                                                <?}else{?>
                                                    <?=childData[j].createTime?>
                                                <?}?>
                                        <?}?>
                                    </td>
                                <?}?>
                                </tr>
                            <?}?>
                            </tbody>
                        </table>
                    </div>
                </div>
            <?}?>
        </script>
        <script>
            var clickMenu = "version-list";
            myPage = 10;
            searchFormId = "#searchVersionForm";
            tableId = "registerId";
            isShowLog = true;
            dataListId = "dataList";
            var $table=$('#table-list');
            var lastVersionNo = '',lastUpTime='';//上次最后版本号
            var downloadPath_url = '';//临时下载脚本url
            var saveVersionFormObj = $("#saveVersionForm");
            var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
            $(".sysEname").val(defSysEname);
            $("#version").text(strUtil.getLocalStorage("current_version"));

            $(function () {
                mytools.cleanData('#saveVersionForm');
                getTableDatas();
                downloadPath_url='';
            });
            //设置页面显示信息
            function  initSetLastInfo(lastNo,lastTime) {
                if(!strUtil.isNull(lastNo)){
                    lastVersionNo = lastNo;
                }
                if(!strUtil.isNull(lastTime)){
                    lastUpTime = lastTime;
                }
                $('#span_last_version').text(lastVersionNo);
                $('#last_up_time').val(lastUpTime);
            }
            //获取下个版本号
            function getNextVersionNum(){
                var nextVersion = '1.0.0';
                var lastVersionNo = $("#span_last_version").text();
                if('无'!=lastVersionNo && !strUtil.isNull(lastVersionNo) && lastVersionNo.indexOf(".")>-1){
                    var vArray = lastVersionNo.split(".");
                    // console.log('thisVersion',thisVersion,vArray);
                    var b=1,s=0,g=0;
                    if(vArray.length==3){
                        b=vArray[0]*1,s=vArray[1]*1,g=vArray[2]*1;
                    }else if(vArray.length==2){
                        b=vArray[0]*1,s=vArray[1]*1;
                    }else if(vArray.length==1) {
                        b=vArray[0]*1;
                    }
                    if(s==9 && g==9){
                        s=0;
                        g=0;
                        b++;
                    }else if(g==9){
                        g=0;
                        s++;
                    }else {
                        g++;
                    }
                    nextVersion=b+"."+s+"."+g;
                }
                console.log('nextVersion',nextVersion);
                saveVersionFormObj.find("input[name='sysVersion.versionNo']").val(nextVersion);
                return nextVersion;
            }

            $('.form_datetime').datetimepicker({
                // container: ".modal-content",
                format: 'yyyy-mm-dd hh:ii:ss',
                /* minView: "month",  *///选择日期后，不会再跳转去选择时分秒
                language: 'zh-CN',
                dateFormat: 'yyyy-mm-dd',//日期显示格式
                timeFormat: 'HH:mm:ss',//时间显示格式
                todayBtn: 1,
                autoclose: 1,
                minView: 0,  //0表示可以选择小时、分钟   1只可以选择小时
                minuteStep: 5,//分钟间隔1分钟
                endDate: new Date()
            });

            //给模态窗口内form表单内的所有支持必填项的元素注入校验
            $(".modal").on('shown.bs.modal', function () {
                $(this).find("form").each(function () {
                    var formId = $(this).attr("id");
                    if (!strUtil.isNull(formId)) {
                        formId = "#" + formId;
                        setValidate(formId);//定义add表单验证属性
                        mytools.cleanValidate(formId);//清空上次校验规则提示
                    }
                });
            });

            //读取（查询、编辑）数据
            function toLoad(id, type) {
                var paramLoadData = {};
                paramLoadData['pageName']="sys-version";
                paramLoadData['formName']="searchForm";

                paramLoadData['sysVersion.w_versionNo']=id;
                $.ajax({
                    type: 'get', url: common_info_url, dataType: 'json',
                    data: paramLoadData,
                    success: function (myData) {
                        //console.log(myData);
                        showData(type, myData);
                    }
                });
            }

            function del(id){
                var index_submit =  layer.confirm('您确认要删除此信息吗？', { btn: ['确认','取消'] },
                    function(){
                        layer.close(index_submit);
                        var index_load = layer.load(1, {shade: false});
                        $.ajax({type:'post', url:common_submit_url, dataType:'json',
                            data:{'pageName':'sys-version','formName':'delForm','sysVersion.w_versionNo':id},
                            success: function(myData){
                                layer.close(index_load);
                                console.log("del.version.res",myData);
                                if(myData.flag=='T'){
                                    getTableDatas();
                                    loadCache();
                                }else{
                                    layer.alert('操作失败：'+myData.msg);
                                }
                            }
                        });
                    },
                    function(){}
                );
            }

            //检查最新版本更新内容
            function getVersionUpCheckListData() {
                var searchLastTime = $('#last_up_time').val();
                if(strUtil.isNull(searchLastTime)){
                    layer.msg('请手动选择上次更新时间');
                    return;
                }
                var checkbox_this_sysname_flag = $("#checkbox_this_sysname").is(":checked");
                var searchSysEname = '';
                if(checkbox_this_sysname_flag){
                    searchSysEname = defSysEname;
                }
                var index_load = layer.msg('正在检查更新内容...',{time:false});
                var nextVersion = getNextVersionNum();
                $.ajax({
                    type: 'get',
                    url: common_list_url,dataType: 'json',
                    data:{"pageName":'sys-version',"formName":"checkForm","searchSysEname":searchSysEname,"searchLastTime":searchLastTime,"currentVersion":nextVersion},
                    success: function (myData) {
                        layer.close(index_load);
                        console.log('checkForm.res',myData);
                        if (myData.flag == "T") {
                            if(myData.total>0){
                                if(myData.msg.indexOf("http")>-1){
                                    downloadPath_url=myData.msg;
                                }
                                $("#span_new_version").text(nextVersion);
                                var data = baidu.template("versionCheck-template",eval(myData));
                                $("#versionCheck-body").html(data);
                                $('.box').boxWidget();
                                var checkResultBodyData = [];
                                $("#versionCheck-body").find("h3[data-code]").each(function () {
                                    var dataObj = this.dataset;
                                    // console.log('dataObj',dataObj);
                                    checkResultBodyData.push(dataObj);
                                });
                                if(checkResultBodyData.length>0){
                                    // console.log('checkResultBodyData',checkResultBodyData);
                                    var remarkContent = {lastUpTime:searchLastTime,data:checkResultBodyData};
                                    saveVersionFormObj.find("textarea[name='sysVersion.remark']").val(JSON.stringify(remarkContent))
                                }
                                $("#span_version_result").removeClass('hidden');
                                $("#box-version-opt").removeClass('hidden');
                                layer.msg('可根据下面1、2步按钮进行升级部署操作！');
                            }else{
                                downloadPath_url='';
                                $("#box-version-opt").addClass('hidden');
                                $("#span_version_result").addClass('hidden');
                                $("#versionCheck-body").html("<div class='fx3'>本次暂无可升级更新的内容！</div>");
                            }
                        }
                    }
                });
            }
            function toCache(versionNo) {
                $.ajax({
                    type: 'get',
                    url: common_cache_url+"view",
                    data:{"cacheSpaceName":'versionCache',"cachekey":"version_"+versionNo},
                    dataType: 'json',
                    success: function (myData) {
                        console.log(myData);
                        if (myData.flag == "T") {
                            layer.open({
                                title: '查看缓存信息',
                                type: 1,
                                skin: 'layui-layer-demo', //样式类名
                                anim: 2,
                                shadeClose: true, //开启遮罩关闭
                                area: ['500px', '300px'],
                                content: "<div style='word-break:break-all;word-wrap:break-word;width:100%;padding:5px;'>" + myData.msg +"</div>"
                            });
                        } else {
                            layer.alert(myData.msg);
                        }
                    }
                });
            }

            function toAdds() {
                mytools.cleanData('#submitForm');
                $("#my_modal").modal("show");

                console.log('localStorage.current_version',strUtil.getLocalStorage("current_version"));

                if (!strUtil.isNull(defSysEname)) {
                    // $("#submitForm").find("input[name='sysVersion.versionNo']").attr("readonly", true).val(defSysEname + "Service");
                    // $("#submitForm").find("input[name='sysVersion.versionNo']").attr("readonly", true);
                }
                $("#submitForm").find("input[name='formName']").val("addForm");
            }

            //反显数据
            function showData(type, myData) {
                console.log("------------------------>",myData);
                FormUtil.loadView("sysVersion", myData["sysVersion"]);
                if ("view" == type) {
                    $("#my_modal_view").modal("show");
                } else if ("edit" == type) {
                    $("#my_modal").modal("show");
                    $("#submitForm").find("input[name='formName']").val("editForm");
                    // initRadio("tInterfaceRegister.flag", myData["tInterfaceRegister"].flag);
                    // initSelect("callType", myData["tInterfaceRegister"].callType);
                }
            }

            //保存版本信息
            function saveVersionForm() {
                var index_submit = layer.confirm('您确认已升级部署完成，并需保存最新版本信息？', { btn: ['确认','取消'] },
                function(){
                    layer.close(index_submit);
                    var index_load = layer.load(1, {shade: false});
                    $.ajax({
                        type: 'post', url: common_submit_url, dataType: 'json',
                        data: saveVersionFormObj.serialize(),
                        success: function (myData) {
                            layer.close(index_load);
                            console.log('saveVersionForm',myData);
                            if (myData.flag == 'T') {
                                layer.msg("保存最新版本信息成功！");
                                getTableDatas();
                                loadCache();
                            }else{
                                layer.alert('操作失败：'+myData.msg);
                            }
                        }
                    });
                },
                function(){}
                );
            }

            //下载脚本
            function downloadDocFile() {
                if(!strUtil.isNull(downloadPath_url)){
                    window.open(downloadPath_url);
                }
            }

            function saveItem(formId) {
                var validate = $('#' + formId).data('bootstrapValidator').validate();
                if (!validate.isValid()) { //如果校验不通过就返回
                    return;
                }
                var index_submit = layer.confirm('确认提交操作吗？', {
                        btn: ['确认', '取消'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        layer.close(index_submit);
                        alert(formId+"|"+common_submit_url);
                        alert($("#" + formId).serialize());

                        $.ajax({
                            type: 'post', url: common_submit_url, dataType: 'json',
                            data: $("#" + formId).serialize(),
                            success: function (myData) {
                                console.log(myData);
                                //layer.alert(myData.msg, {icon: 1,closeBtn: 0,offset: '220px'});
                                if (myData.flag == 'T') {
                                    getTableDatas();
                                    loadCache();
                                    //layer.alert("操作成功", {icon: 1, closeBtn: 0, offset: '220px'});
                                } else {
                                    layer.alert(myData.msg, {
                                        icon: 1,
                                        closeBtn: 0,
                                        offset: '220px'
                                    });
                                }
                                mytools.closeModal("my_modal");
                            }
                        });
                    });
            }

            /**
            function loadCache() {
                $.ajax({
                    type: 'post',
                    url: "${ctx}/protocol/cache.action",
                    dataType: 'json',
                    success: function (myData) {
                        layer.alert(myData.msg, {icon: 1, closeBtn: 0, offset: '220px'});
                        getTableDatas();
                    }
                });
            }**/

            function loadCache() {
                var index_load = layer.load(1, {shade: false});
                $.ajax({
                    type: 'post',
                    url: common_cache_url+"init",
                    data:{"pageName":"sys-version","formName":"initiCacheForm"},
                    dataType: 'json',
                    success: function (myData) {
                        layer.close(index_load);
                        console.log("iusCache.init",myData);
                        if(myData.flag=="T"){
                            $("#version").text(strUtil.getLocalStorage("current_version"));
                            layer.msg("操作成功！");
                        }else{
                            layer.msg(myData.msg);
                        }
                    }
                });
            }

            function getTableDatas() {
                var index_load = layer.load(1, {shade: false});
                $.ajax({
                    type: 'get',
                    url: common_list_url,dataType: 'json',
                    data: $(searchFormId).serialize() + getCurrentPage(common_list_url + "?" + $(searchFormId).serialize(), myPage),
                    success: function (myData) {
                        console.log('dataList.res',myData);
                        if (myData.flag == "T") {
                            if(myData.total>0){
                                layer.close(index_load);
                                var firstRowData = myData.rows[0]['sysVersion'];
                                if(firstRowData.createTime){
                                    initSetLastInfo(firstRowData.versionNo,firstRowData.createTime);
                                }
                                var data = baidu.template("dataListVersion-template",eval(myData));
                                $("#dataListVersion-body").html(data);
                                var option = {
                                    ele: $("#dataListVersion-page")[0],
                                    total: myData.total,
                                    fn: getTableDatas,
                                    url: common_list_url + "?" + $(searchFormId).serialize()
                                };
                                generatePages(option);
                            }else{
                                var sys_createTime_str = '2020-09-10 00:00:00';
                                if('plateform'==defSysEname){
                                    layer.close(index_load);
                                    //开发平台默认值；
                                    initSetLastInfo('无',sys_createTime_str);
                                }else{
                                    $.ajax({
                                        type: 'get',dataType: 'json',
                                        url: common_list_url,
                                        data:{"pageName":"uct-sys-list","formName":"searchForm","uctSys.w_sysEname":defSysEname},
                                        success: function (myData) {
                                            layer.close(index_load);
                                            console.log("getSys.list",myData);
                                            if(myData.flag=="T" && myData.total>0){
                                                if(myData.rows[0]['uctSys'] && !strUtil.isNull(myData.rows[0]['uctSys'].createTime)){
                                                    sys_createTime_str = getFormatDateByLong(myData.rows[0]['uctSys'].createTime,'yyyy-MM-dd hh:mm:ss');
                                                }
                                                initSetLastInfo('首次',sys_createTime_str);
                                            }
                                        }
                                    });
                                }
                                $("#dataListVersion-body").html('');
                            }
                        }
                    }
                });
            }

            function initRadio(elemname, selVl) {
                var myobj = document.getElementsByName(elemname);
                if (myobj == null) return;
                for (var i = 0; i < myobj.length; i++) {
                    if (myobj[i].value == selVl) {
                        myobj[i].checked = "true";
                    }
                }
            }

            function initSelect(elemid, selVl) {
                var myobj = document.getElementById(elemid);
                if (myobj == null) return;
                for (var i = 0; i < myobj.options.length; i++) {
                    if (myobj.options[i].value == selVl) {
                        myobj.selectedIndex = i;
                    }
                }
            }

            //1.定义校验规则-定义
            function setValidate(id) {
                $(id).each(function () {
                    $(this).bootstrapValidator({
                        feedbackIcons: {
                            valid: 'glyphicon glyphicon-ok',
                            invalid: 'glyphicon glyphicon-remove',
                            validating: 'glyphicon glyphicon-refresh'
                        }, /** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
                        fields: {
                            /** 可自定义新增验证规则
                             "uctUser.userEname":{
								validators: {
								regexp: {
								regexp: /^[0-9]+$/,
								message: '只能是数字'
								}
								}
								}
                             **/
                        }
                    });
                });
            }


            function serverStatusFormatter(value) {
                if(value=='0'){
                    return "<font class='red'><i class='fa fa-stop-circle'></i> 已停用</font>";
                }else{
                    return "<font class='blue'><i class='fa fa-area-chart'></i> 已启用</font>";
                }
            }

            function tableOptFormatter(value, row, index) {
                var obj = row.sysVersion;
                var versionNo = obj.versionNo;
                var status = obj.status;
                var htmls ="";
                htmls += "<button type=\"button\" class=\"btn btn-warning btn-xs\" onclick=\"toLoad('"+versionNo+"','edit');\">修改</button>&nbsp;";
                if(status=='0'){
                    htmls += "<button type=\"button\" class=\"btn btn-danger btn-xs\" onclick=\"del('"+versionNo+"');\">删除</button>&nbsp;";
                }
                htmls += "<button type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"toCache('"+versionNo+"');\">查看缓存</button>";
                return htmls;
            }
            function formatOpt(value, row, index) {
                var obj = row.sysVersion;
                var status = obj.status;
                var versionNo = obj.versionNo;
                var htmls ="<i class='fa fa-circle-o' aria-hidden='true' style='cursor: pointer' onclick=\"setCurrentVersion('"+versionNo+"')\"></i>";
                if(status=="1"){
                    htmls ="<i class='fa fa-dot-circle-o' aria-hidden='true' style='cursor: pointer'></i>";
                }

                return htmls;
            }


            function setCurrentVersion(versionNo) {
                var index_load = layer.load(1, {shade: false});
                var currentVersion =  strUtil.getLocalStorage("current_version")
                $.ajax({
                    type: 'post',
                    url: common_submit_url+"?pageName=version-list&formName=setCurrentVersion&ifBatch=T&sysVersion.splitAttr=status&sysVersion.status=1&sysVersion.status=0&sysVersion.w_versionNo="+versionNo+"&sysVersion.w_versionNo="+currentVersion,
                    // data:{"pageName":"version-list","formName":"setCurrentVersion","ifBatch":"T","sysVersion.splitAttr":"status","sysVersion.status":"1","sysVersion.status":"0","sysVersion.w_versionNo":versionNo,"sysVersion.w_versionNo":currentVersion},
                    dataType: 'json',
                    success: function (myData) {
                        layer.close(index_load);
                        if(myData.flag=="T"){
                            loadCache();
                            strUtil.setLocalStorage("current_version",versionNo);
                            getTableDatas();
                            layer.msg("操作成功！");
                        }else{
                            layer.msg(myData.msg);
                        }
                    }
                });
            }

        </script>


    </div>
    <!-- /.content-wrapper -->
    <!-- foot start -->
    <#include "/common/plateform/foot.ftl">
    <!-- foot start -->


</body>


</html>
